/*
 * LITE.cxx
 *
 *  Created on: 9:50:27 AM Nov 1, 2012
 *      Author: Pallab
 * "I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
	double endtime = clock() + (seconds * CLOCKS_PER_SEC);
	while (clock() < endtime) {
		;
	}
}
#define T int
inline T fastIn() {
	register char c = 0;
	register T a = 0;
	bool neg = false;
	while (c < 33)
		c = getchar();
	while (c > 33) {
		if (c == '-') {
			neg = true;
		} else {
			a = (a * 10) + (c - '0');
		}
		c = getchar();
	}
	return neg ? -a : a;
}
const int MX = 100000;
namespace segtree {
#define LEFT(x) (x << 1)
#define RIGHT(x) ( 1 + ( x << 1) )
#define MID(x,y) ( (x + y) >> 1 )
struct Node {
	int s;
	bool u;
	Node() :
			s(0), u(false) {
		;
	}
};
Node t[MX * 4];
void init(int v, int tl, int tr) {
	if (tl == tr) {
		t[v] = Node();
	} else {
		int tm = MID(tl,tr);
		init(LEFT(v), tl, tm);
		init(RIGHT(v), tm + 1, tr);
	}
}
inline int range_sum(int v, int l, int r) {
	if (t[v].u == false)
		return t[v].s;
	return (r - l + 1) - t[v].s;
}
void update(int v, int tl, int tr, int l, int r) {
	if (r < tl || tr < l)
		return;
	if (l <= tl && tr <= r) {
		t[v].u ^= true;
	} else {
		//do lazy propagate
		int tm = MID(tl,tr);
		if (t[v].u == true) {
			t[LEFT(v)].u ^= true;
			t[RIGHT(v)].u ^= true;
			t[v].u = false;
		}
		update(LEFT(v), tl, tm, l, r);
		update(RIGHT(v), tm + 1, tr, l, r);
		t[v].s = range_sum(LEFT(v), tl, tm) + range_sum(RIGHT(v), tm + 1, tr);
	}
}
int get_sum(int v, int tl, int tr, int l, int r) {
	if (r < tl || tr < l)
		return 0;
	if (l <= tl && tr <= r) {
		return range_sum(v, tl, tr);
	} else {
		int tm = MID(tl,tr);
		//do lazy propagate
		if (t[v].u == true) {
			t[LEFT(v)].u ^= true;
			t[RIGHT(v)].u ^= true;
			t[v].u = false;
			t[v].s = range_sum(LEFT(v), tl, tm)
					+ range_sum(RIGHT(v), tm + 1, tr);
		}
		return get_sum(LEFT(v), tl, tm, l, r)
				+ get_sum(RIGHT(v), tm + 1, tr, l, r);
	}
}
}
int node_count, query_count;
inline void main2() {
	node_count = fastIn(), query_count = fastIn();
	int type, l, r, on_count;
	segtree::init(1, 0, node_count - 1);

	fo(i,query_count)
	{
		type = fastIn(), l = fastIn() - 1, r = fastIn() - 1;
		switch (type) {
		case 0:
			//update interval l-r
			segtree::update(1, 0, node_count - 1, l, r);
			break; //
		case 1:
			//query interval l-r;
			on_count = segtree::get_sum(1, 0, node_count - 1, l, r);
			cout << on_count << "\n";
			break;
		default:
			break;
		}
	}
}
int main() {
	int kase = 1;
#if defined( xerxes_pc )
	if (!freopen("in1", "r", stdin))
		puts("error opening file in "), assert(0);
	kase = 1;
#endif
	fo(i,kase)
	{
		main2();
	}
	return 0;
}
